package com.hu.zhcc.shiro.controller;

import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.entity.bo.Member;
import com.hu.zhcc.shiro.entity.vo.MemberVO;
import com.hu.zhcc.shiro.service.MemberService;
import com.hu.zhcc.shiro.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController extends BaseController{
    @Autowired
    MemberService memberService;

    @GetMapping("listAllMember")
    public ResponseEntity<PageInfo<Member>> getMemberList(@RequestParam(required = false) String name,
                                                     @RequestParam(required = false) String sort, int offset, int limit) {

        PageInfo<Member> allMember = memberService.getMemberByName(offset, limit,name);

        return ResponseEntity.ok(allMember);
    }
    @GetMapping("getMember")
    public ResponseEntity<Member> getMember(Integer id) {
        Member member = memberService.getMember(id);
        return ResponseEntity.ok(member);
    }
    @GetMapping("getMemberByIdCard")
    public ResponseEntity<Member> getMemberByIdCard(String  idCard) {
        Member member = memberService.getMember(idCard);
        return ResponseEntity.ok(member);
    }
    @PostMapping("updateMember")
    public ResponseEntity<Integer> updateMember(@RequestBody Member member) {
        int i = memberService.updateMember(member);
        return ResponseEntity.ok(i);
    }
    @PostMapping("addMember")
    public ResponseEntity<Integer> addMember(@RequestBody Member member) {
        int i = memberService.addMember(member);
        return ResponseEntity.ok(i);
    }
    @PostMapping("deleteMember")
    public ResponseEntity<Integer> deleteMember(Integer id) {
        int i = memberService.deleteMember(id);
        return ResponseEntity.ok(i);
    }
}
